package com.xh.bussiness.permission.controller;

import com.xh.bussiness.permission.bean.request.FunctionRequest;
import com.xh.bussiness.permission.service.IFunctionService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "功能接口")
@RestController
@RequestMapping("/permission/function")
public class FunctionController extends BaseController {

    @Autowired
    private IFunctionService functionService;


    @ApiOperation(value = "功能查询",notes = "功能查询")
    @RequestMapping("/queryAll")
    public AjaxResult queryAll(FunctionRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "", functionService.queryFunction(bean));
    }


    @ApiOperation(value = "功能分页查询",notes = "功能分页查询")
    @RequestMapping("/queryPage")
    public AjaxResult queryPage(XhPage page, FunctionRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"",functionService.queryFunctionPage(page,bean));
    }


    @ApiOperation(value = "新增功能",notes = "新增功能")
    @PostMapping(value="/add")
    @Transactional
    public AjaxResult add(FunctionRequest bean){
        String msg=functionService.addFunction(bean);
        return new AjaxResult(msg==null,msg);
    }


    @ApiOperation(value = "修改功能",notes = "修改功能")
    @PostMapping(value="/modify")
    @Transactional
    public AjaxResult modify(FunctionRequest bean){
         String msg=functionService.modifyFunction(bean);
        return new AjaxResult(msg==null,msg);
    }


    @ApiOperation(value = "功能删除",notes = "功能删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "功能id",required = true,dataType = "String")
    })
    @RequestMapping("/delete")
    @Transactional
    public AjaxResult delete(String id){
        String msg=functionService.deleteFunction(id);
        return new AjaxResult(msg==null,msg);
    }

}

